<?php

if (!defined("EXPONENT")) exit("");
	$sermon = null;		
	if (isset($_POST['id'])) {
		$sermon = $db->selectObject('sermonmodule_sermon', 'id='.$_POST['id']);
		if ($sermon != null) {
			$loc = unserialize($sermon->location_data);
		} 
	}
	
	if (exponent_permissions_check("create",$loc) || exponent_permissions_check("administrate",$loc)) {	
		//$config = $db->selectObject('sermonmodule_sermon',"location_data='".serialize($loc)."'");
		
		$sermon= sermonmodule_sermon::update($_POST, $sermon);
		$sermon->location_data = serialize($loc);
		//print_r($sermon);
		//die();
		if (isset($sermon->id)) {
			// calculate all song length
			$db->updateObject($sermon,"sermonmodule_sermon");
		} else {
			$db->insertObject($sermon,"sermonmodule_sermon");
		}		
		
		exponent_flow_redirect();
	} else {
		echo SITE_403_HTML;
	}
	

?>
